//
//  HPYEmoticonPageView.swift
//  SwiftVVBo
//
//  Created by hepeiyong on 16/8/18.
//  Copyright © 2016年 hpyhn. All rights reserved.
//

import UIKit
// cell 可重用标示符
private let HPYEmoticonPageViewCellId = "HPYEmoticonPageViewCellId"
class HPYEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RandomColor()
        // 注册cell
        registerClass(HPYEmoticonPageViewCell.self, forCellWithReuseIdentifier: HPYEmoticonPageViewCellId)
        // 设置代理
        dataSource = self


    }

    override func layoutSubviews() {
        super.layoutSubviews()
        // 设置layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        // 设置item
        layout.itemSize = self.frame.size
        // 设置垂直和水平间距
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        // 滚动方向
        layout.scrollDirection = .Horizontal
    }
}

extension HPYEmoticonPageView: UICollectionViewDataSource {

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 3
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 5
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(HPYEmoticonPageViewCellId, forIndexPath: indexPath) as! HPYEmoticonPageViewCell
        cell.indexPath = indexPath
        return cell
    }
}
